<template>
	<view>
		<u-popup :show="shareShow" :round="true" @close="shareShow = false" @open="open" mode="bottom">
			<view class="sharemodeBox">
				<wm-poster @success="success" :imgSrc="mainImages" :QrSrc="QrSrc" :Title="name" :PriceTxt="memberPrice"
					:OriginalTxt="price"></wm-poster>
				<view v-if='successType' class="sharemodeBox_buttonBox">
					<view class="sharemodeBox_buttonBox_button">
						<u-button @click="shareShow = false" text="取消"></u-button>
					</view>
					<view class="sharemodeBox_buttonBox_button">
						<u-button @click="share" type="primary" text="分享给微信好友"></u-button>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import wmPoster from "@/components/wm-poster/wm-poster.vue"
	export default {
		name: "poster",
		components: {
			wmPoster
		},
		props: {
			mainImages: {},
			memberPrice: {},
			price: {},
			name: {}
		},
		data() {
			return {
				QrSrc: '',
				shareShow: false,
				successType: false,
				user: JSON.parse(uni.getStorageSync('user')),

			};
		},
		methods: {
			chuang(text) {
				this.QrSrc =
					`https://tool.oschina.net/action/qrcode/generate?data=${encodeURIComponent(text)}&output=image%2Fgif&error=L&type=0&margin=0&size=4&1646030986871`
				this.shareShow = true;
			},
			share() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 2,
					imageUrl: this.successUrl,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			open() {

			},
			openshare(text) {
				this.chuang(text);
				uni.showLoading({
					title: '加载中',
					mask: true
				});
			},
			success(e) {
				// console.log(e.tempFilePath)
				this.successType = true
				this.successUrl = e.tempFilePath
				uni.hideLoading()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.sharemodeBox {
		width: 100%;
		// height: 20%;
		position: fixed;
		top: 0;
		left: 50%;
		transform: translate(-50%);

		.sharemodeBox_buttonBox {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.sharemodeBox_buttonBox_button {
				width: 50%;
				padding: 20upx 40upx;
			}
		}
	}
</style>
